home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
win
/
general
/
atree.exe
/
lha
/
MOSQUITO.ZIP
/
MOSQUITO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-05
|
8KB
|
209 lines
/*****************************************************************************
**** ****
**** mosquito.c ****
**** ****
**** Copyright (C) A. Dwelly and W.W. Armstrong, 1990. ****
**** ****
**** All rights reserved. ****
**** ****
**** Attachment of copyright does not imply publication. ****
**** This file contains information which is proprietary ****
**** to the authors. ****
**** ****
**** This is a test of the research version of the adaptive logic ****
**** network package atree. This particular program demonstrates the ****
**** algorithm's ability to extract a simple relationship from complex ****
**** data. ****
**** ****
**** Each entry in the training set represents a human about which ****
**** 80 facts are known, represented by randomly setting bits. The ****
**** function _mosquito()_ is a single bit which is set if the patient ****
**** has been bitten by a mosquito (bit 1) is not taking quinine (bit 7) ****
**** and does not have sickle cell anemia (bit 12). The programer is free****
**** to increase the difficulty of the experiment by modifying the ****
**** initial constants. ****
**** ****
**** As the program is set up, the algorithm is searching in a space ****
**** of 2^80 bits, that is, 1208925819614629174706176 seperate bit ****
**** patterns, from this, it sees a mere 500 (a fraction of 1% of the ****
**** possible patterns) but correctly deduces the relationship between ****
**** the known facts, and the health of the patients. ****
**** ****
**** The adaptive logic network package based on work done by Prof. W. ****
**** W. Armstrong and others in the Department of Computing Science, ****
**** University of Alberta, and previous work at the Universite de ****
**** Montreal, and at AT&T Bell Laboratories, Holmdel, N. J. The ****
**** software demonstrates that networks consisting of many layers of ****
**** linear threshold elements can indeed be effectively trained. ****
**** ****
**** License: ****
**** A royalty-free license is granted for the use of this software for ****
**** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and ****
**** modified provided this notice appears in its entirety and unchanged ****
**** in all copies, whether changed or not. Persons modifying the code ****
**** are requested to state the date, the changes made and who made them ****
**** in the modification history. ****
**** ****
**** Warranty: ****
**** No warranty of any kind is provided with this software. ****
**** This software is not supported. Neither the authors, nor the ****
**** University of Alberta, its officers, agents, servants or employees ****
**** shall be liable or responsible in any way for any damage to ****
**** property or direct personal or consequential injury of any nature ****
**** whatsoever that may be suffered or sustained by any licensee, user ****
**** or any other party as a consequence of the use or disposition of ****
**** this software. ****
**** ****
**** Patent: ****
**** The use of a digital circuit which transmits a signal indicating ****
**** heuristic responsibility is protected by U. S. Patent 3,934,231 ****
**** and others assigned to Dendronic Decisions Limited of Edmonton, ****
**** W. W. Armstrong, President. ****
**** ****
**** Modification history: ****
**** ****
**** 5.9.90 Initial implementation, A.Dwelly ****
**** 31.5.91 Windows Port & Windows Extensions, M. Thomas ****
**** ****
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "atree.h"
#define VERBOSITY 0
#define TRAINSETSIZE 500
#define WIDTH 80
#define TREESIZE 256
#define TESTSIZE 500
#define BITTEN 1
#define QUININE 7
#define ANEMIA 12
#define Printf(str,fmt1,fmt2) \
{ \
char Buff[80]; \
sprintf(Buff, str, fmt1, fmt2); \
MessageBox(hwnd, Buff, "Mosquito", MB_OK); \
}
char mosquito(v)
char *v;
{
return(v[BITTEN] && (!v[QUININE]) && (!v[ANEMIA]));
}
BOOL NEAR PASCAL main(HWND hwnd)
{
int i;
int j;
int malaria = 0;
int healthy = 0;
char vec[WIDTH];
char ui[1];
int correct = 0;
LPBIT_VEC training_set;
LPBIT_VEC icres;
LPBIT_VEC test;
LPATREE tree;
HCURSOR hCursor;
/* Initialise */
training_set = (LPBIT_VEC) Malloc(TRAINSETSIZE * sizeof(bit_vec));
MEMCHECK(training_set);
icres = (LPBIT_VEC) Malloc(TRAINSETSIZE * sizeof(bit_vec));
MEMCHECK(icres);
atree_init();
/* Create the test data */
Printf("Creating training data\n",0,0); /* Printf macro takes three arguments */
for (i = 0; i < TRAINSETSIZE; i++)
{
/* allow multitasking during long loop! */
Windows_Interrupt(2000);
for (j = 0; j < WIDTH; j++)
{
vec[j] = (char)RANDOM(2);
}
training_set[i] = *(bv_pack(vec, WIDTH));
ui[0] = mosquito(vec);
if (ui[0])
{
malaria++;
}
else
{
healthy++;
}
icres[i] = *(bv_pack(ui,1));
}
Printf("There are %d patients with malaria, and %d healthy in the training set\n",malaria,healthy);
/* Create a tree and train it */
Printf("Training tree\n",0,0);
tree = atree_create(WIDTH,TREESIZE);
(void) atree_train(tree,training_set,icres,0,TRAINSETSIZE,
TRAINSETSIZE-1,10,1);
/* Test the trained tree */
Printf("Testing the tree\n",0,0);
for (i = 0; i < TESTSIZE; i++)
{
/* allow multitasking during long loop! */
Windows_Interrupt(2000);
for (j = 0; j < WIDTH; j++)
{
vec[j] = RANDOM(2);
}
test = bv_pack(vec,WIDTH);
if (atree_eval(tree,test) == mosquito(vec))
{
correct++;
}
bv_free(test);
}
Printf("%d correct out of %d in final test\n",correct,TESTSIZE);
/* Discard training set */
Printf("Please wait, discarding training set",0,0);
hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
ShowCursor(TRUE);
for (i =